package com.teach.mapper;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.repository.query.Param;

import com.teach.dto.ShopOrderDTO;
import com.teach.dto.ShopOrderItemSearch;
import com.teach.dto.ShopOrderSearch;
import com.teach.entity.ShopOrderItem;

import lombok.experimental.PackagePrivate;

public interface ShopOrderItemMapper {
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table shop_order_item
     *
     * @mbg.generated
     */
    int deleteByPrimaryKey(Long shopOrderItemId);
    
    @Delete("DELETE t1,t2\r\n" + 
    		"from shop_order t1 \r\n" + 
    		"LEFT JOIN shop_order_item t2\r\n" + 
    		"on t1.SHOP_ORDER_ID=t2.SHOP_ORDER_ID\r\n" + 
    		"where t2.SHOP_ORDER_ITEM_ID=#{orderId}")
    int deleteByOrderId(@Param("orderId")Long orderId);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table shop_order_item
     *
     * @mbg.generated
     */
    int insert(ShopOrderItem record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table shop_order_item
     *
     * @mbg.generated
     */
    int insertSelective(ShopOrderItem record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table shop_order_item
     *
     * @mbg.generated
     */
    @Update("UPDATE shop_order_item set SHOP_ORDER_ITEM_PAY_TIME=#{paytime} where SHOP_ORDER_ID=#{orderID}")
    int updateByoid(@Param("paytime")Date paytime,@Param("orderID")Long orderID);
    
    ShopOrderItem selectByPrimaryKey(Long shopOrderItemId);
    
    @Select("select * from shop_order_item where SHOP_ORDER_ID=#{productId}")
    ShopOrderItem selectById(@Param("productId")Long productId);
    		
    		/**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table shop_order_item
     *
     * @mbg.generated
     */
    int updateByPrimaryKeySelective(ShopOrderItem record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table shop_order_item
     *
     * @mbg.generated
     */
    int updateByPrimaryKey(ShopOrderItem record);
    
    List<ShopOrderDTO> select(ShopOrderSearch search);
    
    List<ShopOrderItem> selects(ShopOrderItemSearch search);
    @Update("update shop_order s,shop_order_item ss\r\n" + 
    		"set s.SHOP_ORDER_STATE=#{state},ss.SHOP_ORDER_ITEM_STATE=#{state}\r\n" + 
    		"where s.SHOP_ORDER_ID=ss.SHOP_ORDER_ID and ss.SHOP_ORDER_ITEM_ID=#{orderId}")
    int update(@Param("state")Integer state,@Param("orderId")Long orderId);//修改订单状态
    
    @Update("update shop_order s,shop_order_item ss\r\n" + 
    		"set s.SHOP_ORDER_STATE=#{state},ss.SHOP_ORDER_ITEM_STATE=#{state}\r\n" + 
    		"where s.SHOP_ORDER_ID=ss.SHOP_ORDER_ID and ss.SHOP_ORDER_ID=#{orderId}")
    int updates(@Param("state")Integer state,@Param("orderId")Long orderId);//修改订单状态
}